package com.production.CoursePlatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.production.CoursePlatform.entity.LearnReplay;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LearnReplayMapper extends BaseMapper<LearnReplay> {

    // 创建新的学习回复，无需lr_id，自动生成lr_id
    @Insert("INSERT INTO learn_replay (ct_id, lr_date, lr_order, attachment) " +
            "VALUES (#{ctID}, #{lrDate}, #{lrOrder}, #{attachment})")
    void insertLearnReplay(LearnReplay learnReplay);

    // 根据lr_id查找学习回放
    @Select("SELECT * FROM learn_replay WHERE lr_id = #{lrID}")
    LearnReplay selectByLrId(@Param("lrID") int lrID);

    // 根据cmt_id查找学习回放
    @Select("SELECT * FROM learn_replay WHERE ct_id = #{ctID}")
    List<LearnReplay> selectByCtId(@Param("ctID") int ctID);

    // 删除指定lr_id的学习回放
    @Delete("DELETE FROM learn_replay WHERE lr_id = #{lrID}")
    int deleteByLrId(@Param("lrID") int lrID);

    // 更新学习回放内容
    @Update("UPDATE learn_replay SET ct_id = #{ctID}, lr_date = #{lrDate}, lr_order = #{lrOrder}, " +
            "attachment = #{attachment} WHERE lr_id = #{lrID}")
    int updateLearnReplay(LearnReplay learnReplay);
}
